import hashlib
import json

import requests
from util.time_stamp import get_time_stamp
from util.headers import get_header

results = []
results_set = set()


while True:
    url = f"https://api.live.bilibili.com/xlive/web-interface/v1/index/getList?platform=web&web_location=444.7&w_rid=d3078c67ac0e6ed1a4c35410d147226b&wts={get_time_stamp()}"
    res = requests.get(url, headers=get_header())
    on = True
    for item in res.json()["data"]["room_list"][1]["list"]:
        print(item)
        item_hash = hashlib.md5(json.dumps(item).encode()).hexdigest()
        if item_hash not in results_set:
            results_set.add(item_hash)
            results.append(item)
            if len(results) == 100:
                go_on = False
                break
        else:
            print(f"发现重复项0...........")
    if not on:
        break
    print(f"数据为{len(results)}{len(results_set)}")
